import { resolve } from 'path';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import { PROJECT_PATH, isDev } from '../constants.js';


const PLUGINS = [
	// 配置html，自动引入打包出的js文件
	new HtmlWebpackPlugin({
		template: resolve(PROJECT_PATH, './public/index.html'),
		filename: 'index.html',
		cache: false,
		minify: isDev
			? false
			: {
					removeAttributeQuotes: true,
					collapseWhitespace: true,
					removeComments: true,
					collapseBooleanAttributes: true,
					collapseInlineTagWhitespace: true,
					removeRedundantAttributes: true,
					removeScriptTypeAttributes: true,
					removeStyleLinkTypeAttributes: true,
					minifyCSS: true,
					minifyJS: true,
					minifyURLs: true,
					useShortDoctype: true,
				},
	}),
];

export default {
  mode: isDev ? 'development' : 'production',
  entry: {
    app: resolve(PROJECT_PATH, './src/index.js'),
  },
  output: {
      filename: 'js/[name].[hash:8].js', // 指定输出文件的名称。
      path: resolve(PROJECT_PATH, './dist'),
  },
  plugins: PLUGINS,
};